//hooks
// export default function IndexPage() {

//   function testCoffee(params){
//     console.log(params);
//     this.props.dispatch({ type: 'user/login', payload: values });
//   }


//   return (
//     <div>
//       <h1 className="title">Show me the UI!</h1>
//       <button onClick={testCoffee.bind(this, '1')}>点我</button>
//     </div>
//   );
// }

import React from 'react';
import { connect } from 'dva';
@connect(state => ({
  coffee: state.coffee,
  testtest:state.testtest
}))
// @connect()
class IndexPage extends React.Component {

  testCoffee(params){
    console.log(params);
    //需要@connect()连接dva中的model
    this.props.dispatch({ type: 'index/testCoffee', payload: params });
  }


  //JSX允许{}花括号内，出现表达式，三元表达式，注释，数组，样式，变量；花括号内的变量允许是JSX，三元运算符的后面允许是JSX
  render(){
    console.log('render',this.coffee);
    const element = (
      <div>
        <h1 className="title">Show me the UI!</h1>
        <button onClick={this.testCoffee.bind(this, 'mocha')}>点我</button>
        <h2>现在是 {new Date().toLocaleTimeString()}.</h2>
        <span>{this.coffee}</span>
        <span>{this.testtest}</span>
      </div>
    );

    return element;
  }
}
export default IndexPage;

// import{ connect } from ‘dva’;
// function mapStateToProps(state){
// return{ todos: state.todos };
// }
// connect(mapStateToProps)(App);


